﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Collections;

namespace Agresso.Interface.Layer.Domain
{
    public class BunkerPO
    {
        public string supplier = string.Empty;
        public string supplier_quotation = string.Empty;
        public string profit_centre_fullname = string.Empty;
        public DateTime stemmed_date = DateTime.Today;
        public string voyage_no = string.Empty;
        public decimal quantity_stemmed = 0;
        public decimal price_gross = 0;
        public decimal expense_broker = 0;
        public decimal expense_delivery = 0;
        public string lifting_status = string.Empty;
        public DateTime due = DateTime.Today;
        public DateTime enquiry_date = DateTime.Today;
        public string enquiry_no = string.Empty;
        public string enquiry_status = string.Empty;
        public string vessel = string.Empty;
        public string port = string.Empty;
        public string buyer = string.Empty;
        public string buyer_remarks = string.Empty;
        public DateTime delivery_date = DateTime.Today;
        public string grade = string.Empty;
        public decimal delivery_lumpsum_price = 0;
        public decimal price_per_mt = 0;
        public int quotation_id = 0;
        public string quotation_status = string.Empty;
        public string operated_by = string.Empty;
        public decimal est_qty_max = 0;

        public int po_interface_id = 0;
        public string pickup_flag = string.Empty;
        public DateTime pickup_date = new DateTime(1900, 1, 1);
        public DateTime pickup_update_date = new DateTime(1900, 1, 1);
        public DateTime insert_date = new DateTime(1900, 1, 1);
        public string headerdetail = "H"; //header detail
        public string remarks = ""; //header detail
        public string batch_id = ""; 

        public GradeAccountMapping GradeAccountMapping = null;
        public string delivery_lumpsum = "61890001";
        public string delivery_lumpsum_unit = "UN";

        public IList Items = new ArrayList();
        public IList ItemsAndQuotation = new ArrayList();
        public int ItemLineNumber = 0;
        public bool IsAllItemIsValid = true;
        public Vessel Vessel;
        public ProfitCentre ProfitCentre;
        public SupplierCustomer Supplier;
        public string short_info = "";
        public string vessel_code = string.Empty;


        public BunkerPO() { }
        public BunkerPO(string enquiryNo) { enquiry_no = enquiryNo; }
        public BunkerPO(SqlDataReader rd, bool isfrominterface)
        {
            enquiry_no = rd["enquiry_no"] is DBNull ? "" : rd["enquiry_no"].ToString();
            enquiry_date = rd["enquiry_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["enquiry_date"]);
            vessel = rd["vessel"] is DBNull ? "" : rd["vessel"].ToString();
            port = rd["port"] is DBNull ? "" : rd["port"].ToString();
            buyer = rd["buyer"] is DBNull ? "" : rd["buyer"].ToString();
            buyer_remarks = rd["buyer_remarks"] is DBNull ? "" : rd["buyer_remarks"].ToString();
            delivery_date = rd["delivery_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["delivery_date"]);
            supplier = rd["supplier"] is DBNull ? "" : rd["supplier"].ToString();
            grade = rd["grade"] is DBNull ? "" : rd["grade"].ToString();
            delivery_lumpsum_price = rd["delivery_lumpsum_price"] is DBNull ? 0 : Convert.ToDecimal(rd["delivery_lumpsum_price"]);
            price_per_mt = rd["price_per_mt"] is DBNull ? 0 : Convert.ToDecimal(rd["price_per_mt"]);
            quotation_id = rd["quotation_id"] is DBNull ? 0 : Convert.ToInt32(rd["quotation_id"]);
            supplier_quotation = rd["supplier_quotation"] is DBNull ? "" : rd["supplier_quotation"].ToString();
            quotation_status = rd["quotation_status"] is DBNull ? "" : rd["quotation_status"].ToString();
            stemmed_date = rd["stemmed_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["stemmed_date"]);
            quantity_stemmed = rd["quantity_stemmed"] is DBNull ? 0 : Convert.ToDecimal(rd["quantity_stemmed"]);
            enquiry_status = rd["enquiry_status"] is DBNull ? "" : rd["enquiry_status"].ToString();
            profit_centre_fullname = rd["profit_centre_fullname"] is DBNull ? "" : rd["profit_centre_fullname"].ToString();
            voyage_no = rd["voyage_no"] is DBNull ? "" : rd["voyage_no"].ToString();
            price_gross = rd["price_gross"] is DBNull ? 0 : Convert.ToDecimal(rd["price_gross"]);
            expense_broker = rd["expense_broker"] is DBNull ? 0 : Convert.ToDecimal(rd["expense_broker"]);
            expense_delivery = rd["expense_delivery"] is DBNull ? 0 : Convert.ToDecimal(rd["expense_delivery"]);
            lifting_status = rd["lifting_status"] is DBNull ? "" : rd["lifting_status"].ToString();
            due = rd["due"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["due"]);
            operated_by = rd["operated_by"] is DBNull ? "" : rd["operated_by"].ToString();
            //quotation_status = rd["delivery_lumpsum"] is DBNull ? "" : rd["delivery_lumpsum"].ToString();
            //quotation_status = rd["delivery_lumpsum_unit"] is DBNull ? "" : rd["delivery_lumpsum_unit"].ToString();
            vessel_code = rd["vessel_code"] is DBNull ? "" : rd["vessel_code"].ToString();
            est_qty_max = rd["est_qty_max"] is DBNull ? 0 : Convert.ToDecimal(rd["est_qty_max"]);
            if (isfrominterface)
            {
                pickup_flag = rd["pickup_flag"] is DBNull ? "" : rd["pickup_flag"].ToString();
                pickup_date = rd["pickup_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_date"]);
                pickup_update_date = rd["pickup_update_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_update_date"]);
                insert_date = rd["insert_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["insert_date"]);
                po_interface_id = rd["po_interface_id"] is DBNull ? 0 : Convert.ToInt32(rd["po_interface_id"]);
                headerdetail = rd["headerdetail"] is DBNull ? "" : rd["headerdetail"].ToString();
                remarks = rd["remarks"] is DBNull ? "" : rd["remarks"].ToString();
                batch_id = rd["batch_id"] is DBNull ? "" : rd["batch_id"].ToString();
            }
        }
        public BunkerPO(SqlDataReader rd)
        {
            enquiry_no = rd["enquiry_no"] is DBNull ? "" : rd["enquiry_no"].ToString();
            enquiry_date = rd["enquiry_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["enquiry_date"]);
            pickup_date = rd["pickup_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_date"]);
            remarks = rd["remarks"] is DBNull ? "" : rd["remarks"].ToString();
        }
    }
}
